﻿#region 文件信息

// FileName: SoCafeShop/Sohobloo.SoMcCoffee.Public/Md5.cs
// Author: Sohobloo
// CreateTime: 2013/06/29 22:50
// UpdateTime: 2013/06/30 3:41

#endregion

#region 引用

using System.Security.Cryptography;
using System.Text;

#endregion

namespace Sohobloo.SoMcCoffee.Public.Security
{
    public static class Md5
    {
        #region 枚举

        private const string Salt = "sohobloo";

        #endregion 枚举

        #region 方法

        public static byte[] GetMd5(string content)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            var data = Encoding.Default.GetBytes(content); //将字符编码为一个字节序列 
            var md5Data = md5.ComputeHash(data); //计算data字节数组的哈希值 
            md5.Clear();
            return md5Data;
        }

        public static byte[] GetSaltedMd5(string content, string salt)
        {
            content += salt;
            return GetMd5(content);
        }

        public static byte[] GetSaltedMd5(string content)
        {
            return GetSaltedMd5(content, Salt);
        }

        #endregion 方法
    }
}